<!-- 智能表单设置页面 -->
<template>
    <div class="create-project-box">
        <div class="create-title">填写实例信息</div>

        <div class="create-form-box">
            <el-form :rules="rules" ref="ruleForm" :model="form" label-width="100px" label-position="left">
                <el-form-item label="项目名称" prop="title">
                    <el-input v-model="form.title"></el-input>
                </el-form-item>
                <el-form-item label="项目简介" prop="desc">
                    <el-input type="textarea" v-model="form.desc"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary"  @click="submitForm('ruleForm')">立即创建</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
export default {
    name: "CreateForm",
    data(){
        return {
            form: {
              title: '',
              desc: ''
            },
            rules: {
                title: [
                    { required: true, message: '请输入项目名称', trigger: 'blur' },
                    { min: 2, max: 60, message: '长度在 2 到 60 个字符', trigger: 'blur' }
                ],
                desc: [
                    { required: true, message: '请填写项目简介', trigger: 'blur' },
                    { min: 4, max: 200, message: '长度在 4 到 200 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    methods:{
        //设置表单
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$message.success('表单实例创建完成');

                    setTimeout(() => {
                        this.$router.push({ path : '/editor/', query : { instance_id : 1 } });
                    }, 2000);
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
    }
}
</script>

<style lang="scss" scoped>
    @import "../../assets/theme";

    .create-project-box{
        width: 480px;
        margin: 0 auto;
    }


</style>